#include "Array3D.h"

CArray3D::CArray3D(int xsize, int ysize, int zsize)
: xs(xsize), ys(ysize), zs(zsize)
{
	if (xsize<=0 || ysize<=0 || zsize<=0)
		throw BadSize();

	arr3D = new int**[xsize];
	
	for(int i=0; i<xsize; i++)
	{
		arr3D[i] = new int*[ysize];
		for(int j=0; j<ysize; j++)
			arr3D[i][j] = new int[zsize];
	}
}

CArray3D::~CArray3D(void)
{
	for(int i=0; i<xs; i++)
	{
		for(int j=0; j<ys; j++)
			delete [] arr3D[i][j];
		delete [] arr3D[i];
	}
	delete [] arr3D;
}

int& CArray3D::operator() (int x, int y, int z)
{
	if (x>=xs || y>=ys || z>=zs || x<0 || y<0 || z<0)
		throw BoundsViolations();
	return arr3D[x][y][z];
}

const int& CArray3D::operator() (int x, int y, int z) const
{
	if (x>=xs || y>=ys || z>=zs || x<0 || y<0 || z<0)
		throw BoundsViolations();
	return arr3D[x][y][z];
}
